﻿using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Csla;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace RMSM
{
    [Serializable()]
    public class KBDienTimBO : Csla.BusinessBase<KBDienTimBO>
    {
        #region Business Properties

        private int? _KBDienTimID = null;
        public int? KBDienTimID
        {
            get { return this._KBDienTimID; }
            set { this._KBDienTimID = value; PropertyHasChanged("KBDienTimID"); }
        }

        private int? _Status = 0;
        public int? Status
        {
            get { return this._Status; }
            set { this._Status = value; PropertyHasChanged("Status"); }
        }

        private int? _KBDieuTriID = null;
        public int? KBDieuTriID
        {
            get { return this._KBDieuTriID; }
            set { this._KBDieuTriID = value; PropertyHasChanged("KBDieuTriID"); }
        }

        private int? _KBYLenhID = null;
        public int? KBYLenhID
        {
            get { return this._KBYLenhID; }
            set { this._KBYLenhID = value; PropertyHasChanged("KBYLenhID"); }
        }

        private int? _BenhNhanID = null;
        public int? BenhNhanID
        {
            get { return this._BenhNhanID; }
            set { this._BenhNhanID = value; PropertyHasChanged("BenhNhanID"); }
        }

        private int? _NguoiChiDinhID = null;
        public int? NguoiChiDinhID
        {
            get { return this._NguoiChiDinhID; }
            set { this._NguoiChiDinhID = value; PropertyHasChanged("NguoiChiDinhID"); }
        }

        private DateTime? _NgayChiDinh = null;
        public DateTime? NgayChiDinh
        {
            get { return this._NgayChiDinh; }
            set { this._NgayChiDinh = value; PropertyHasChanged("NgayChiDinh"); }
        }

        private int? _NguoiThucHienID = null;
        public int? NguoiThucHienID
        {
            get { return this._NguoiThucHienID; }
            set { this._NguoiThucHienID = value; PropertyHasChanged("NguoiThucHienID"); }
        }

        private DateTime? _NgayThucHien = null;
        public DateTime? NgayThucHien
        {
            get { return this._NgayThucHien; }
            set { this._NgayThucHien = value; PropertyHasChanged("NgayThucHien"); }
        }

        private int? _KhoaThucHienID = null;
        public int? KhoaThucHienID
        {
            get { return this._KhoaThucHienID; }
            set { this._KhoaThucHienID = value; PropertyHasChanged("KhoaThucHienID"); }
        }

        private int? _PhongThucHienID = null;
        public int? PhongThucHienID
        {
            get { return this._PhongThucHienID; }
            set { this._PhongThucHienID = value; PropertyHasChanged("PhongThucHienID"); }
        }

        private int? _DMDienTimID = null;
        public int? DMDienTimID
        {
            get { return this._DMDienTimID; }
            set { this._DMDienTimID = value; PropertyHasChanged("DMDienTimID"); }
        }

        private string _KyThuat = null;
        public string KyThuat
        {
            get { return this._KyThuat; }
            set { this._KyThuat = value; PropertyHasChanged("KyThuat"); }
        }

        private string _TinhTrang = null;
        public string TinhTrang
        {
            get { return this._TinhTrang; }
            set { this._TinhTrang = value; PropertyHasChanged("TinhTrang"); }
        }

        private string _Nhip = null;
        public string Nhip
        {
            get { return this._Nhip; }
            set { this._Nhip = value; PropertyHasChanged("Nhip"); }
        }

        private string _TanSo = null;
        public string TanSo
        {
            get { return this._TanSo; }
            set { this._TanSo = value; PropertyHasChanged("TanSo"); }
        }

        private string _Goc = null;
        public string Goc
        {
            get { return this._Goc; }
            set { this._Goc = value; PropertyHasChanged("Goc"); }
        }

        private string _Truc = null;
        public string Truc
        {
            get { return this._Truc; }
            set { this._Truc = value; PropertyHasChanged("Truc"); }
        }

        private string _P = null;
        public string P
        {
            get { return this._P; }
            set { this._P = value; PropertyHasChanged("P"); }
        }

        private string _PQ = null;
        public string PQ
        {
            get { return this._PQ; }
            set { this._PQ = value; PropertyHasChanged("PQ"); }
        }

        private string _QRS = null;
        public string QRS
        {
            get { return this._QRS; }
            set { this._QRS = value; PropertyHasChanged("QRS"); }
        }

        private string _ST = null;
        public string ST
        {
            get { return this._ST; }
            set { this._ST = value; PropertyHasChanged("ST"); }
        }

        private string _T = null;
        public string T
        {
            get { return this._T; }
            set { this._T = value; PropertyHasChanged("T"); }
        }

        private string _QT = null;
        public string QT
        {
            get { return this._QT; }
            set { this._QT = value; PropertyHasChanged("QT"); }
        }

        private string _DTDCCC = null;
        public string DTDCCC
        {
            get { return this._DTDCCC; }
            set { this._DTDCCC = value; PropertyHasChanged("DTDCCC"); }
        }

        private string _DTTTim = null;
        public string DTTTim
        {
            get { return this._DTTTim; }
            set { this._DTTTim = value; PropertyHasChanged("DTTTim"); }
        }

        private byte[] _Anh = null;
        public byte[] Anh
        {
            get { return this._Anh; }
            set { this._Anh = value; PropertyHasChanged("Anh"); }
        }

        private string _KetQua = null;
        public string KetQua
        {
            get { return this._KetQua; }
            set { this._KetQua = value; PropertyHasChanged("KetQua"); }
        }

        private string _KetLuan = null;
        public string KetLuan
        {
            get { return this._KetLuan; }
            set { this._KetLuan = value; PropertyHasChanged("KetLuan"); }
        }

        private string _GhiChu = null;
        public string GhiChu
        {
            get { return this._GhiChu; }
            set { this._GhiChu = value; PropertyHasChanged("GhiChu"); }
        }

        private double? _GiaTien = 0;
        public double? GiaTien
        {
            get { return this._GiaTien; }
            set { this._GiaTien = value; PropertyHasChanged("GiaTien"); }
        }

        private int? _UserCreated = Session.LoginID;
        public int? UserCreated
        {
            get { return this._UserCreated; }
            set { this._UserCreated = value; PropertyHasChanged("UserCreated"); }
        }

        private DateTime? _DateCreated = DateTime.MaxValue;
        public DateTime? DateCreated
        {
            get { return this._DateCreated; }
            set { this._DateCreated = value; PropertyHasChanged("DateCreated"); }
        }

        private int? _UserModify = null;
        public int? UserModify
        {
            get { return this._UserModify; }
            set { this._UserModify = value; PropertyHasChanged("UserModify"); }
        }

        private DateTime? _DateModify = null;
        public DateTime? DateModify
        {
            get { return this._DateModify; }
            set { this._DateModify = value; PropertyHasChanged("DateModify"); }
        }

        private bool? _Deleted = false;
        public bool? Deleted
        {
            get { return this._Deleted; }
            set { this._Deleted = value; PropertyHasChanged("Deleted"); }
        }

        private int? _STT0 = 0;
        public int? STT0
        {
            get { return _STT0; }
            set { _STT0 = value; }
        }

        protected override object GetIdValue()
        {
            return _KBDienTimID.Value;
        }
        #endregion Business Properties
        //==========================================================================

        #region Factory Methods
        public void SetIsNew()
        {
            MarkNew();
        }

        public void SetIsOld()
        {
            MarkOld();
        }

        public void SetIsDirty()
        {
            MarkDirty();
        }

        public void SetIsChild()
        {
            MarkAsChild();
        }

        public object GetValue(string fieldName)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            return propInfo.GetValue(this, null);
        }

        public void SetValue(string fieldName, object value)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            propInfo.SetValue(this, value, null);
            MarkDirty();
        }

        private static int newKBDienTimID = -1;
        private KBDienTimBO()
        {
            _KBDienTimID = newKBDienTimID--;
        }

        public KBDienTimBO(SqlDataReader dataReader)
        {
            MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public KBDienTimBO(SqlDataReader dataReader, bool isRoot)
        {
            if (!isRoot)
                MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public static KBDienTimBO NewRootKBDienTimBO()
        {
            return DataPortal.Create<KBDienTimBO>(new RootCriteria());
        }

        internal static KBDienTimBO NewChildKBDienTimBO()
        {
            return DataPortal.Create<KBDienTimBO>(new ChildCriteria());
        }

        public static KBDienTimBO GetRootKBDienTimBO(int _KBDienTimID)
        {
            return DataPortal.Fetch<KBDienTimBO>(new RootCriteria(_KBDienTimID));
        }

        public static KBDienTimBO GetRootKBDienTimBOByWhere(string where)
        {
            return DataPortal.Fetch<KBDienTimBO>(where);
        }

        internal static KBDienTimBO GetChildKBDienTimBO(SqlDataReader dataReader)
        {
            return new KBDienTimBO(dataReader);
        }

        public static void DeleteKBDienTimBO(int _KBDienTimID)
        {
            DataPortal.Delete(new RootCriteria(_KBDienTimID));
        }

        public static void DeleteKBDienTimBO(int _KBDienTimID, bool directDelete)
        {
            DataPortal.Delete(new RootCriteria(_KBDienTimID, directDelete));
        }
        #endregion Factory Methods
        //==========================================================================

        #region Criteria
        [Serializable()]
        public class RootCriteria
        {
            public int KBDienTimID;
            public bool directDelete = false;
            public RootCriteria(int _KBDienTimID)
            {
                this.KBDienTimID = _KBDienTimID;
                this.directDelete = false;
            }

            public RootCriteria(int _KBDienTimID, bool directDelete)
            {
                this.KBDienTimID = _KBDienTimID;
                this.directDelete = directDelete;
            }

            public RootCriteria() { }
        }

        [Serializable()]
        public class ChildCriteria
        {
            public int KBDienTimID;
            public bool directDelete = false;
            public ChildCriteria(int _KBDienTimID)
            {
                this.KBDienTimID = _KBDienTimID;
                this.directDelete = false;
            }

            public ChildCriteria(int _KBDienTimID, bool directDelete)
            {
                this.KBDienTimID = _KBDienTimID;
                this.directDelete = directDelete;
            }

            public ChildCriteria() { }
        }
        #endregion Criteria
        //==========================================================================

        #region Create
        [RunLocal]
        private void DataPortal_Create(RootCriteria criteria)
        {
        }

        private void DataPortal_Create(ChildCriteria criteria)
        {
            MarkAsChild();
            ValidationRules.CheckRules();
        }

        #endregion Create
        //==========================================================================

        #region Fetch
        [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Fetch(RootCriteria criteria)
        {
            this.Execute_Fetch(criteria);
        }

        protected void DataPortal_Fetch(string where)
        {
            this.Execute_Fetch(where);
        }

        protected void Execute_Fetch(RootCriteria criteria)
        {
            this.This_Fetch(criteria);
        }

        protected void Execute_Fetch(string where)
        {
            this.This_Fetch(where);
        }

        private void This_Fetch(RootCriteria criteria)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienTimBO_GetBO");
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, "[KBDienTimID] = " + criteria.KBDienTimID);
            using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
            {
                if (dataReader.Read())
                    Fetch(dataReader);
            }
        }

        private void This_Fetch(string where)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienTimBO_GetBO");
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, where);
            using (SqlDataReader dataReader = (SqlDataReader)db.ExecuteReader(cmd))
            {
                if (dataReader.Read())
                    Fetch(dataReader);
            }
        }

        private void Fetch(SqlDataReader dataReader)
        {
            if (!(dataReader["KBDienTimID"] is DBNull))
                this._KBDienTimID = (int)dataReader["KBDienTimID"];
            if (!(dataReader["Status"] is DBNull))
                this._Status = (int)dataReader["Status"];
            if (!(dataReader["KBDieuTriID"] is DBNull))
                this._KBDieuTriID = (int)dataReader["KBDieuTriID"];
            if (!(dataReader["KBYLenhID"] is DBNull))
                this._KBYLenhID = (int)dataReader["KBYLenhID"];
            if (!(dataReader["BenhNhanID"] is DBNull))
                this._BenhNhanID = (int)dataReader["BenhNhanID"];
            if (!(dataReader["NguoiChiDinhID"] is DBNull))
                this._NguoiChiDinhID = (int)dataReader["NguoiChiDinhID"];
            if (!(dataReader["NgayChiDinh"] is DBNull))
                this._NgayChiDinh = (DateTime)dataReader["NgayChiDinh"];
            if (!(dataReader["NguoiThucHienID"] is DBNull))
                this._NguoiThucHienID = (int)dataReader["NguoiThucHienID"];
            if (!(dataReader["NgayThucHien"] is DBNull))
                this._NgayThucHien = (DateTime)dataReader["NgayThucHien"];
            if (!(dataReader["KhoaThucHienID"] is DBNull))
                this._KhoaThucHienID = (int)dataReader["KhoaThucHienID"];
            if (!(dataReader["PhongThucHienID"] is DBNull))
                this._PhongThucHienID = (int)dataReader["PhongThucHienID"];
            if (!(dataReader["DMDienTimID"] is DBNull))
                this._DMDienTimID = (int)dataReader["DMDienTimID"];
            if (!(dataReader["KyThuat"] is DBNull))
                this._KyThuat = (string)dataReader["KyThuat"];
            if (!(dataReader["TinhTrang"] is DBNull))
                this._TinhTrang = (string)dataReader["TinhTrang"];
            if (!(dataReader["Nhip"] is DBNull))
                this._Nhip = (string)dataReader["Nhip"];
            if (!(dataReader["TanSo"] is DBNull))
                this._TanSo = (string)dataReader["TanSo"];
            if (!(dataReader["Goc"] is DBNull))
                this._Goc = (string)dataReader["Goc"];
            if (!(dataReader["Truc"] is DBNull))
                this._Truc = (string)dataReader["Truc"];
            if (!(dataReader["P"] is DBNull))
                this._P = (string)dataReader["P"];
            if (!(dataReader["PQ"] is DBNull))
                this._PQ = (string)dataReader["PQ"];
            if (!(dataReader["QRS"] is DBNull))
                this._QRS = (string)dataReader["QRS"];
            if (!(dataReader["ST"] is DBNull))
                this._ST = (string)dataReader["ST"];
            if (!(dataReader["T"] is DBNull))
                this._T = (string)dataReader["T"];
            if (!(dataReader["QT"] is DBNull))
                this._QT = (string)dataReader["QT"];
            if (!(dataReader["DTDCCC"] is DBNull))
                this._DTDCCC = (string)dataReader["DTDCCC"];
            if (!(dataReader["DTTTim"] is DBNull))
                this._DTTTim = (string)dataReader["DTTTim"];
            if (!(dataReader["Anh"] is DBNull))
                this._Anh = (byte[])dataReader["Anh"];
            if (!(dataReader["KetQua"] is DBNull))
                this._KetQua = (string)dataReader["KetQua"];
            if (!(dataReader["KetLuan"] is DBNull))
                this._KetLuan = (string)dataReader["KetLuan"];
            if (!(dataReader["GhiChu"] is DBNull))
                this._GhiChu = (string)dataReader["GhiChu"];
            if (!(dataReader["GiaTien"] is DBNull))
                this._GiaTien = (double)dataReader["GiaTien"];
            if (!(dataReader["UserCreated"] is DBNull))
                this._UserCreated = (int)dataReader["UserCreated"];
            if (!(dataReader["DateCreated"] is DBNull))
                this._DateCreated = (DateTime)dataReader["DateCreated"];
            if (!(dataReader["UserModify"] is DBNull))
                this._UserModify = (int)dataReader["UserModify"];
            if (!(dataReader["DateModify"] is DBNull))
                this._DateModify = (DateTime)dataReader["DateModify"];
            if (!(dataReader["Deleted"] is DBNull))
                this._Deleted = (bool)dataReader["Deleted"];

        }
        #endregion Fetch
        //==========================================================================

        #region Insert
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Insert()
        {
            this.Execute_Insert();
        }

        protected void Execute_Insert()
        {
            this.This_Insert();
        }

        private void This_Insert()
        {
            this._UserCreated = Session.LoginID;
            this._DateCreated = DateTime.MaxValue;
            this._UserModify = null;
            this._DateModify = null;
            this._Deleted = false;

            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienTimBO_InsertBO");
            db.AddInParameter(cmd, "@Status", SqlDbType.Int, this._Status);
            db.AddInParameter(cmd, "@KBDieuTriID", SqlDbType.Int, this._KBDieuTriID);
            db.AddInParameter(cmd, "@KBYLenhID", SqlDbType.Int, this._KBYLenhID);
            db.AddInParameter(cmd, "@BenhNhanID", SqlDbType.Int, this._BenhNhanID);
            db.AddInParameter(cmd, "@NguoiChiDinhID", SqlDbType.Int, this._NguoiChiDinhID);
            db.AddInParameter(cmd, "@NgayChiDinh", SqlDbType.DateTime, this._NgayChiDinh);
            db.AddInParameter(cmd, "@NguoiThucHienID", SqlDbType.Int, this._NguoiThucHienID);
            db.AddInParameter(cmd, "@NgayThucHien", SqlDbType.DateTime, this._NgayThucHien);
            db.AddInParameter(cmd, "@KhoaThucHienID", SqlDbType.Int, this._KhoaThucHienID);
            db.AddInParameter(cmd, "@PhongThucHienID", SqlDbType.Int, this._PhongThucHienID);
            db.AddInParameter(cmd, "@DMDienTimID", SqlDbType.Int, this._DMDienTimID);
            db.AddInParameter(cmd, "@KyThuat", SqlDbType.NVarChar, this._KyThuat);
            db.AddInParameter(cmd, "@TinhTrang", SqlDbType.NVarChar, this._TinhTrang);
            db.AddInParameter(cmd, "@Nhip", SqlDbType.NVarChar, this._Nhip);
            db.AddInParameter(cmd, "@TanSo", SqlDbType.NVarChar, this._TanSo);
            db.AddInParameter(cmd, "@Goc", SqlDbType.NVarChar, this._Goc);
            db.AddInParameter(cmd, "@Truc", SqlDbType.NVarChar, this._Truc);
            db.AddInParameter(cmd, "@P", SqlDbType.NVarChar, this._P);
            db.AddInParameter(cmd, "@PQ", SqlDbType.NVarChar, this._PQ);
            db.AddInParameter(cmd, "@QRS", SqlDbType.NVarChar, this._QRS);
            db.AddInParameter(cmd, "@ST", SqlDbType.NVarChar, this._ST);
            db.AddInParameter(cmd, "@T", SqlDbType.NVarChar, this._T);
            db.AddInParameter(cmd, "@QT", SqlDbType.NVarChar, this._QT);
            db.AddInParameter(cmd, "@DTDCCC", SqlDbType.NVarChar, this._DTDCCC);
            db.AddInParameter(cmd, "@DTTTim", SqlDbType.NVarChar, this._DTTTim);
            db.AddInParameter(cmd, "@Anh", SqlDbType.Image, this._Anh);
            db.AddInParameter(cmd, "@KetQua", SqlDbType.NVarChar, this._KetQua);
            db.AddInParameter(cmd, "@KetLuan", SqlDbType.NVarChar, this._KetLuan);
            db.AddInParameter(cmd, "@GhiChu", SqlDbType.NVarChar, this._GhiChu);
            db.AddInParameter(cmd, "@GiaTien", SqlDbType.Float, this._GiaTien);
            db.AddInParameter(cmd, "@UserCreated", SqlDbType.Int, this._UserCreated);
            db.AddOutParameter(cmd, "@NewKBDienTimID", SqlDbType.Int, 10);
            db.AddOutParameter(cmd, "@NewDateCreated", SqlDbType.DateTime, 4);
            db.ExecuteNonQuery(cmd);
            this._KBDienTimID = (int)cmd.Parameters["@NewKBDienTimID"].Value;
            this._DateCreated = (DateTime)cmd.Parameters["@NewDateCreated"].Value;
        }
        #endregion Insert
        //==========================================================================

        #region Update
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
            this.Execute_Update();
        }

        protected void Execute_Update()
        {
            this.This_Update();
        }

        private void This_Update()
        {
            this._UserModify = Session.LoginID;
            this._DateModify = DateTime.Now;

            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienTimBO_UpdateBO");
            db.AddInParameter(cmd, "@KBDienTimID", SqlDbType.Int, this._KBDienTimID);
            db.AddInParameter(cmd, "@Status", SqlDbType.Int, this._Status);
            db.AddInParameter(cmd, "@KBDieuTriID", SqlDbType.Int, this._KBDieuTriID);
            db.AddInParameter(cmd, "@KBYLenhID", SqlDbType.Int, this._KBYLenhID);
            db.AddInParameter(cmd, "@BenhNhanID", SqlDbType.Int, this._BenhNhanID);
            db.AddInParameter(cmd, "@NguoiChiDinhID", SqlDbType.Int, this._NguoiChiDinhID);
            db.AddInParameter(cmd, "@NgayChiDinh", SqlDbType.DateTime, this._NgayChiDinh);
            db.AddInParameter(cmd, "@NguoiThucHienID", SqlDbType.Int, this._NguoiThucHienID);
            db.AddInParameter(cmd, "@NgayThucHien", SqlDbType.DateTime, this._NgayThucHien);
            db.AddInParameter(cmd, "@KhoaThucHienID", SqlDbType.Int, this._KhoaThucHienID);
            db.AddInParameter(cmd, "@PhongThucHienID", SqlDbType.Int, this._PhongThucHienID);
            db.AddInParameter(cmd, "@DMDienTimID", SqlDbType.Int, this._DMDienTimID);
            db.AddInParameter(cmd, "@KyThuat", SqlDbType.NVarChar, this._KyThuat);
            db.AddInParameter(cmd, "@TinhTrang", SqlDbType.NVarChar, this._TinhTrang);
            db.AddInParameter(cmd, "@Nhip", SqlDbType.NVarChar, this._Nhip);
            db.AddInParameter(cmd, "@TanSo", SqlDbType.NVarChar, this._TanSo);
            db.AddInParameter(cmd, "@Goc", SqlDbType.NVarChar, this._Goc);
            db.AddInParameter(cmd, "@Truc", SqlDbType.NVarChar, this._Truc);
            db.AddInParameter(cmd, "@P", SqlDbType.NVarChar, this._P);
            db.AddInParameter(cmd, "@PQ", SqlDbType.NVarChar, this._PQ);
            db.AddInParameter(cmd, "@QRS", SqlDbType.NVarChar, this._QRS);
            db.AddInParameter(cmd, "@ST", SqlDbType.NVarChar, this._ST);
            db.AddInParameter(cmd, "@T", SqlDbType.NVarChar, this._T);
            db.AddInParameter(cmd, "@QT", SqlDbType.NVarChar, this._QT);
            db.AddInParameter(cmd, "@DTDCCC", SqlDbType.NVarChar, this._DTDCCC);
            db.AddInParameter(cmd, "@DTTTim", SqlDbType.NVarChar, this._DTTTim);
            db.AddInParameter(cmd, "@Anh", SqlDbType.Image, this._Anh);
            db.AddInParameter(cmd, "@KetQua", SqlDbType.NVarChar, this._KetQua);
            db.AddInParameter(cmd, "@KetLuan", SqlDbType.NVarChar, this._KetLuan);
            db.AddInParameter(cmd, "@GhiChu", SqlDbType.NVarChar, this._GhiChu);
            db.AddInParameter(cmd, "@GiaTien", SqlDbType.Float, this._GiaTien);
            db.AddInParameter(cmd, "@UserModify", SqlDbType.Int, this._UserModify);
            db.AddInParameter(cmd, "@Deleted", SqlDbType.Bit, this._Deleted);

            db.AddOutParameter(cmd, "@NewDateModify", SqlDbType.DateTime, 4);
            db.ExecuteNonQuery(cmd);

            this._DateModify = (DateTime)cmd.Parameters["@NewDateModify"].Value;
        }
        #endregion Update
        //==========================================================================

        #region Delete
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            DataPortal_Delete(new RootCriteria(_KBDienTimID.Value));
        }

        private void DataPortal_Delete(RootCriteria criteria)
        {
            this.Execute_Delete(criteria);
        }

        protected void Execute_Delete(RootCriteria criteria)
        {
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("KBDienTimBO_DeleteBO");
            db.AddInParameter(cmd, "@DirectDelete", SqlDbType.Bit, criteria.directDelete);
            db.AddInParameter(cmd, "@KBDienTimID", SqlDbType.Int, criteria.KBDienTimID);
            db.ExecuteNonQuery(cmd);
        }
        #endregion Delete
        //==========================================================================

        #region Internal method
        internal void Insert()
        {
            if (!this.IsDirty) return;
            DataPortal_Insert();
            MarkOld();
        }

        internal void Update()
        {
            if (!this.IsDirty) return;
            DataPortal_Update();
            MarkOld();
        }

        internal void DeleteSelf()
        {
            if (!this.IsDirty) return;
            if (this.IsNew) return;
            DataPortal_Delete(new RootCriteria(_KBDienTimID.Value));
            MarkNew();
        }
        #endregion Internal method
        //==========================================================================
    }
}
